ZF.add('native-array', function(Z) {

    var L = Z.Lang;

    Z.Array = {

        each : L.each,
        
        every : L.every,

        filter : L.filter,

        indexOf : L.indexOf,

        map : L.map,

        some : L.some,

        clean : function(arr) {
            return arr.filter(function(v) {
                return v !== undefined;
            });
        },

        link: function(arr, object){
            var result = {};
            for (var i = 0, l = arr.length; i < l; i++){
                for (var key in object){
                    if (object[key](arr[i])){
                        result[key] = arr[i];
                        delete object[key];
                        break;
                    }
                }
            }
            return result;
        },

        contains: function(item, from){
            return this.indexOf(item, from) != -1;
        },

        extend: function(arr, array){
            for (var i = 0, j = array.length; i < j; i++) {
                arr.push(array[i]);
            }
            return arr;
        },

        include: function(arr, item){
            if (!arr.contains(item)) {
                arr.push(item);
            }
            return arr;
        },

        erase: function(arr, item){
            for (var i = arr.length; i--; i) {
                if (arr[i] === item) {
                    arr.splice(i, 1);
                }
            }
            return arr;
        },

        flatten: function(arr){
            var array = [];
            for (var i = 0, l = arr.length; i < l; i++) {
                var type = Z.type(arr[i]);
                if (!type) {
                    continue;
                }
                array = array.concat((type == 'array' || type == 'collection' || type == 'arguments') ? this.flatten(arr[i]) : arr[i]);
            }
            return array;
        }
    };

});